ccR.Unit = {
	Angle = 
	function(unit, other)
		unit = unit or "target"
		other = other or "player"
		if ccR.Unit.Exists(unit) and UnitIsVisible(unit) and ccR.Unit.Exists(other) and UnitIsVisible(other) then
			local X1,Y1 = ObjectPosition(other)
			local R = ObjectFacing(other)
			local X2,Y2 = ObjectPosition(unit)
			local LX=(X2-X1)*math.cos(-R)-(Y2-Y1)*math.sin(-R)
			local LY=(X2-X1)*math.sin(-R)+(Y2-Y1)*math.cos(-R)
			local final = atan(math.abs(LY)/LX)
			if final < 0 then final = final+180 end
			return final
		end
	end, -- donated by Ssateneth
	CanAttack = function(unit, other) return ccR.Unit.Can.Attack(unit, other) end,
	Cast_Time = 
	function(unit)
		if ccR.Unit.Exists(unit)
		and ccR.Unit.Is.Casting(unit)
		then
			local name, _, _, _, _, endTime = UnitCastingInfo(unit)	
			if name ~= nil then	
				local vCastTime = ((endTime/1000) - GetTime())
				if vCastTime then
					return vCastTime
				end
			end
		end
	end,
	Channel_Time = 
	function(unit)
		if ccR.Unit.Exists(unit)
		and ccR.Unit.Is.Channeling(unit)
		then
			local name, _, _, _, _, endTime = UnitChannelInfo(unit)
			if name ~= nil then	
				local vChannelTime = ((endTime/1000) - GetTime())
				if vChannelTime then
					return vChannelTime
				end
			end
		end
	end,
	Class = function(unit) if ccR.Unit.Exists(unit) then vName, vClass, vID = UnitClass(unit); if vID == 1 then return "Warrior" elseif vID == 2 then return "Paladin" elseif vID == 3 then return "Hunter" elseif vID == 4 then return "Rogue" elseif vID == 5 then return "Priest" elseif vID == 6 then return "Death Knight" elseif vID == 7 then return "Shaman" elseif vID == 8 then return "Mage" elseif vID == 9 then return "Warlock" elseif vID == 10 then return "Monk" elseif vID == 11 then return "Druid" end end end,
	Count = 
	function(unit, yards)
		if ccR.Unit.Exists(unit) then
			local vCount = 0 
			for x = 1, # ccR_Enemies do
				local vObject = ccR_Enemies[x] 
				if ccR.Unit.Is.Attackable(vObject, "player")
				--and ccR.Unit.Is.InLineOfSight(vObject, "player")
				and ccR.Unit.Name(vObject) ~= "Unknown"
				and not ccR.Unit.Is.APet(vObject)
				--and not ccR.tblIgnoreNPC[ccR.Unit.NPCID(vObject)]
				--and not ccR.Unit.Is.CC(vObject)
				and (
						(unit == "player" and ccR.Unit.Distance(vObject, "player") <= yards) 
						or
						(unit ~= "player" and ccR.Unit.Distance(vObject, unit, "raw") <= yards)
					) 
				then
					vCount = vCount + 1
				end
			end	
			return vCount
		else
			return 0
		end
	end,
	Friendly_Count = 
	function(unit, yards)
		if ccR.Unit.Exists(unit) then
			local vCount = 0 
			for i = 1, # ccR_Friendly do
				local vObject = ccR_Friendly[i]
				if ccR.Unit.Name(vObject) ~= "Unknown"
				and not ccR.Unit.Is.APet(vObject)
				--and not ccR.tblIgnoreNPC[ccR.Unit.NPCID(vObject)]
				--and not ccR.Unit.Is.CC(vObject)
				and (
						(unit == "player" and ccR.Unit.Distance(vObject, "player") <= yards) 
						or
						(unit ~= "player" and ccR.Unit.Distance(vObject, unit, "raw") <= yards)
					) 
				then
					vCount = vCount + 1
				end
			end	
			return vCount
		else
			return 0
		end
	end,
	CreatureType = function(unit) return UnitCreatureType(unit) end,
	Distance =
	function(unit, other, raw)
		other = other or "player" 
		if ccR.Unit.Exists(unit)
		and ccR.Unit.Exists(other)
		then
			local X1,Y1,Z1 = ObjectPosition(unit) 
			local X2,Y2,Z2 = ObjectPosition(other) 
			local vDistance = math.sqrt(((X2-X1)^2)+((Y2-Y1)^2)+((Z2-Z1)^2)) 
			if raw ~= nil then
				return vDistance 
			else
				local vNotThePlayer 
				if unit == "player" then vNotThePlayer = other else vNotThePlayer = unit end
				return vDistance-UnitCombatReach(vNotThePlayer)
			end
		else 
			return 99999
		end
	end,
	Exists = 
	function(unit)
		if FireHack then
			--if FH(ObjectExists, unit) then return true else return false end
			if ObjectExists(unit) then return true else return false end
		else
			if UnitExists(unit) and UnitIsVisible(unit) then return true else return false end			
		end
	end,
	GUID = function(unit) if ccR.Unit.Exists(unit) then return UnitGUID(unit) end end,
	Health = 
	function(unit, sort)
		if ccR.Unit.Exists(unit) then
			if sort == nil then return (UnitHealth(unit)/UnitHealthMax(unit)*100) end
			if sort == "max" then return UnitHealthMax(unit) end
			if sort == "hp" then return UnitHealth(unit) end
		else
			return 0
		end
	end,
	Level = function(unit) if ccR.Unit.Exists(unit) then return UnitLevel(unit) end end,
	Mana = 
	function(unit, sort) 
		if ccR.Unit.Exists(unit) then
			if sort == nil then return ((UnitPower(unit)/UnitPowerMax(unit))*100)  end
			if sort == "max" then return UnitPowerMax(unit) end
			if sort == "hp" then return UnitPower(unit) end
		else
			return 0
		end
	end,
	Name = function(unit) if ccR.Unit.Exists(unit) then local vName = UnitName(unit); return vName end end,
	NPCID = function(unit) if ccR.Unit.Exists(unit) then return tonumber(strmatch(UnitGUID(unit) or "", "-(%d+)-%x+$"), 10) or tonumber(strsub(UnitGUID(unit) or "", 6, 10), 16) end end,
	Race = function(unit) if ccR.Unit.Exists(unit) then local vRace = UnitRace(unit); return vRace end end,
	Realm = function(unit) if ccR.Unit.Exists(unit) then local vName, vRealm = UnitName(unit); return vRealm end end,
	TargetName = function(unit) if ccR.Unit.Exists(unit) then if unit ~= nil and UnitName(unit) ~= nil and UnitTarget(unit) ~= nil and (ObjectType(unit) == 9 or ObjectType(unit) == 65561 or ObjectType(unit) == 65545) then local vName = UnitName(UnitTarget(unit)) if vName ~= nil then return vName else return nil end else return nil end end end,
	TimeToDie = function(unit) if ccR.Unit.Exists(unit) then local guid = UnitGUID(unit) if deathTrack[unit] and deathTrack[unit].guid == guid then local start = deathTrack[unit].time local currentHP = UnitHealth(unit) local maxHP = deathTrack[unit].start local diff = maxHP - currentHP local dura = GetTime() - start local hpps = diff / dura local death = currentHP / hpps if death == math.huge then return 8675309 elseif death < 0 then return 0 else return death end elseif deathTrack[unit] then ccR.table_empty(deathTrack[unit]) else deathTrack[unit] = { } end deathTrack[unit].guid = guid deathTrack[unit].time = GetTime() deathTrack[unit].start = UnitHealth(unit) return 8675309 end end, -- by phelps --
	-- 
	Can = {
		Attack = function(unit, other) if ccR.Unit.Exists(unit) and ccR.Unit.Exists(other) then if UnitCanAttack(unit, other) then return true else return false end end end,
	},
	Aura = {
		Exists = function(unit, aura, my)
			if my == nil then my = false end
			if ccR.Unit.Exists(unit) 
			and aura ~= nil
			then 
				local SpellIDtoName
				local GetSpellInfoNumber
				if tonumber(aura) ~= nil then 
					local name, rank, icon, castingTime, minRange, maxRange, spellID = GetSpellInfo(aura)
					SpellIDtoName = name
					GetSpellInfoNumber = spellID
				end
				-- Harmful
				for i = 1, 40 do
					local name, rank, icon, count, dispelType, duration, expires, caster, isStealable, shouldConsolidate, spellID, canApplyAura, isBossDebuff, value1, value2, value3 = UnitAura(unit, i, "HARMFUL")
					if name == nil then break end
					if (name == aura or	name == SpellIDtoName or spellID == aura or spellID == GetSpellInfoNumber)
					and (not my or (my and (caster == "player" or caster == "pet")))
					then 
						return true
					end
				end
				-- Helpful
				for i = 1, 40 do
					local name, rank, icon, count, dispelType, duration, expires, caster, isStealable, shouldConsolidate, spellID, canApplyAura, isBossDebuff, value1, value2, value3 = UnitAura(unit, i, "HELPFUL")
					if name == nil then break end
					if (name == aura or	name == SpellIDtoName or spellID == aura or spellID == GetSpellInfoNumber) 
					and (not my or (my and (caster == "player" or caster == "pet")))
					then 
						return true
					end
				end
				return false
			else
				return false
			end
		end,
		Stacks = function(unit, aura, my)
			if my == nil then my = false end
			if ccR.Unit.Exists(unit) 
			and aura ~= nil
			then 
				local SpellIDtoName
				if tonumber(aura) ~= nil then 
					local name, rank, icon, castingTime, minRange, maxRange, spellID = GetSpellInfo(aura)
					SpellIDtoName = name
				end
				-- Harmful
				for i = 1, 40 do
					local name, rank, icon, count, dispelType, duration, expires, caster, isStealable, shouldConsolidate, spellID, canApplyAura, isBossDebuff, value1, value2, value3 = UnitAura(unit, i, "HARMFUL")
					if name == nil then return false end
					if (name == aura or name == SpellIDtoName or spellID == aura) 
					and (not my or (my and (caster == "player" or caster == "pet")))
					then 
						return count
					end
				end
				-- Helpful
				for i = 1, 40 do
					local name, rank, icon, count, dispelType, duration, expires, caster, isStealable, shouldConsolidate, spellID, canApplyAura, isBossDebuff, value1, value2, value3 = UnitAura(unit, i, "HELPFUL")
					if name == nil then return false end
					if (name == aura or name == SpellIDtoName or spellID == aura) 
					and (not my or (my and (caster == "player" or caster == "pet")))
					then 
						return count
					end
				end
				return 0
			else
				return 0
			end
		end,
		Duration = function(unit, aura, by, number, my)
			if my == nil then my = false end
			if ccR.Unit.Exists(unit) 
			and aura ~= nil
			then 
				local SpellIDtoName
				if tonumber(aura) ~= nil then 
					local name, rank, icon, castingTime, minRange, maxRange, spellID = GetSpellInfo(aura)
					SpellIDtoName = name
				end
				local AuraExpires = nil
				-- Harmful
				for i = 1, 40 do
					local name, rank, icon, count, dispelType, duration, expires, caster, isStealable, shouldConsolidate, spellID, canApplyAura, isBossDebuff, value1, value2, value3 = UnitAura(unit, i, "HARMFUL")
					if name == nil then return false end
					if (name == aura or name == SpellIDtoName or spellID == aura) 
					and (not my or (my and (caster == "player" or caster == "pet")))
					then 
						AuraExpires = expires-GetTime()
					end
				end
				-- Helpful
				for i = 1, 40 do
					local name, rank, icon, count, dispelType, duration, expires, caster, isStealable, shouldConsolidate, spellID, canApplyAura, isBossDebuff, value1, value2, value3 = UnitAura(unit, i, "HELPFUL")
					if name == nil then return false end
					if (name == aura or name == SpellIDtoName or spellID == aura) 
					and (not my or (my and (caster == "player" or caster == "pet")))
					then 
						AuraExpires = expires-GetTime()
					end
				end
				if AuraExpires == nil then return false end
				if AuraExpires ~= nil then
					if by == "<" and AuraExpires < number then return true
					elseif by == "<=" and AuraExpires <= number then return true
					elseif by == ">" and AuraExpires > number then return true
					elseif by == ">=" and AuraExpires >= number then return true
					elseif (by == "=" or by == "==") and AuraExpires == number then return true
					elseif by == nil or number == nil then return AuraExpires
					else return false
					end
				end
			else
				return false
			end
		end,
	},
	Buff = {
		Duration = function(unit, buff, by, number, my)
			if my == nil then my = false end
			if ccR.Unit.Exists(unit) 
			and ccR.Unit.Has.Buff(unit, buff) 
			then
				if tonumber(buff) ~= nil then 
					local name, rank, icon, castingTime, minRange, maxRange, spellID = GetSpellInfo(buff)
					SpellIDtoName = name
				end
				local BuffExpires = nil
				for i = 1, 40 do
					local name, rank, icon, count, debuffType, duration, expirationTime, unitCaster, isStealable, shouldConsolidate, spellId = UnitBuff(unit, i)
					if name == nil then return false end
					if (name == buff or name == SpellIDtoName or spellId == buff) 
					and (not my or (my and (unitCaster == "player" or unitCaster == "pet")))
					then 
						BuffExpires = expirationTime-GetTime() 
						break
					end
				end
				if BuffExpires == nil then return false end
				if BuffExpires ~= nil then
					if by == "<" and BuffExpires < number then return true
					elseif by == "<=" and BuffExpires <= number then return true
					elseif by == ">" and BuffExpires > number then return true
					elseif by == ">=" and BuffExpires >= number then return true
					elseif (by == "=" or by == "==") and BuffExpires == number then return true
					elseif by == nil or number == nil then return BuffExpires
					else return false
					end
				end
			else
				return false
			end
		end,
		Exists = function(unit, buff, my)
			if my == nil then my = false end
			if ccR.Unit.Exists(unit) 
			and buff ~= nil
			then 
				local SpellIDtoName
				if tonumber(buff) ~= nil then 
					local name, rank, icon, castingTime, minRange, maxRange, spellID = GetSpellInfo(buff)
					SpellIDtoName = name
				end
				for i = 1, 40 do
					local name, rank, icon, count, debuffType, duration, expirationTime, unitCaster, isStealable, shouldConsolidate, spellId = UnitBuff(unit, i)
					if name == nil then return false end
					if (name == buff or name == SpellIDtoName or spellId == buff) 
					and (not my or (my and (unitCaster == "player" or unitCaster == "pet")))
					then 
						return true
					end
				end
			else
				return false
			end 		
		end,
		Stacks = function(unit, buff, my) 
			if my == nil then my = false end
			if ccR.Unit.Exists(unit) 
			and ccR.Unit.HasBuff(unit, buff) 
			then 
				local SpellIDtoName
				if tonumber(buff) ~= nil then 
					local name, rank, icon, castingTime, minRange, maxRange, spellID = GetSpellInfo(buff)
					SpellIDtoName = name
				end
				for i = 1, 40 do
					local name, rank, icon, count, debuffType, duration, expirationTime, unitCaster, isStealable, shouldConsolidate, spellId = UnitBuff(unit, i)
					if name == nil then return false end
					if (name == buff or name == SpellIDtoName or spellId == buff) 
					and (not my or (my and (unitCaster == "player" or unitCaster == "pet")))
					then 
						return count
					end
				end
			else
				return 0
			end
		end,
	},
	Debuff = {
		Exists = function(unit, debuff, my) 
			if my == nil then my = false end
			if ccR.Unit.Exists(unit) 
			and debuff ~= nil
			then
				local SpellIDtoName
				if tonumber(debuff) ~= nil then 
					local name, rank, icon, castingTime, minRange, maxRange, spellID = GetSpellInfo(debuff)
					SpellIDtoName = name
				end
				for i = 1, 40 do
					local name, rank, icon, count, debuffType, duration, expirationTime, unitCaster, isStealable, shouldConsolidate, spellId = UnitDebuff(unit, i)
					if name == nil then return false end
					if (name == debuff or name == SpellIDtoName or spellId == debuff) 
					and (not my or (my and (unitCaster == "player" or unitCaster == "pet")))
					then 
						return true
					end
				end
				return false
			else
				return false
			end
		end,
		Stacks = function(unit, debuff, my)
			if my == nil then my = false end
			if ccR.Unit.Exists(unit) 
			and ccR.Unit.Debuff.Exists(unit, debuff) 
			then 
				local SpellIDtoName
				if tonumber(debuff) ~= nil then 
					local name, rank, icon, castingTime, minRange, maxRange, spellID = GetSpellInfo(debuff)
					SpellIDtoName = name
				end
				for i = 1, 40 do
					local name, rank, icon, count, debuffType, duration, expirationTime, unitCaster, isStealable, shouldConsolidate, spellId = UnitDebuff(unit, i)
					if name == nil then return false end
					if (name == debuff or name == SpellIDtoName or spellId == debuff) 
					and (not my or (my and (unitCaster == "player" or unitCaster == "pet")))
					then 
						return count
					end
				end
				return 0
			else
				return 0
			end
		end,
		Duration = function(unit, debuff, by, number, my)
			if my == nil then my = false end
			if ccR.Unit.Exists(unit) 
			and ccR.Unit.Debuff.Exists(unit, debuff) 
			then
				local SpellIDtoName
				if tonumber(debuff) ~= nil then 
					local name, rank, icon, castingTime, minRange, maxRange, spellID = GetSpellInfo(debuff)
					SpellIDtoName = name
				end
				local DebuffExpires = nil
				for i = 1, 40 do
					local name, rank, icon, count, debuffType, duration, expirationTime, unitCaster, isStealable, shouldConsolidate, spellId = UnitDebuff(unit, i)
					if name == nil then return false end
					if (name == debuff or name == SpellIDtoName or spellId == debuff) 
					and (not my or (my and (unitCaster == "player" or unitCaster == "pet")))
					then 
						DebuffExpires = expirationTime-GetTime()
						break
					end
				end
				if DebuffExpires == nil then return false end
				if DebuffExpires ~= nil then
					if by == "<" and DebuffExpires < number then return true
					elseif by == "<=" and DebuffExpires <= number then return true
					elseif by == ">" and DebuffExpires > number then return true
					elseif by == ">=" and DebuffExpires >= number then return true
					elseif (by == "=" or by == "==") and DebuffExpires == number then return true
					elseif by == nil or number == nil then return DebuffExpires
					else return false
					end
				end
			else
				return false
			end
		end,
	},	
	My = {
		Aura = {
			Exists = function(unit, aura) return ccR.Unit.Aura.Exists(unit, aura, true) end,
			Duration = function(unit, aura, by, number) return ccR.Unit.Aura.Duration(unit, aura, by, number, true) end,
			Stacks = function(unit, aura) return ccR.Unit.Aura.Stacks(unit, aura, true) end,
		},
		Buff = {
			Exists = function(unit, buff) return ccR.Unit.Buff.Exists(unit, buff, true) end,
			Duration = function(unit, buff, by, number) return ccR.Unit.Buff.Duration(unit, buff, by, number, true) end,
			Stacks = function(unit, buff) return ccR.Unit.Buff.Stacks(unit, buff, true) end,
		},
		Debuff = {
			Exists = function(unit, debuff) return ccR.Unit.Debuff.Exists(unit, debuff, true) end,
			Duration = function(unit, debuff, by, number) return ccR.Unit.Debuff.Duration(unit, debuff, by, number, true) end,
			Stacks = function(unit, debuff) return ccR.Unit.Debuff.Stacks(unit, debuff, true) end,
		},
	},
	Has = {
		Aura = function(unit, aura) return ccR.Unit.Aura.Exists(unit, aura) end,
		Buff = function(unit, buff) return ccR.Unit.Buff.Exists(unit, buff) end,
		CC = function(unit) return ccR.Unit.Is.CC(unit) end,
		Debuff = function(unit, debuff) return ccR.Unit.Debuff.Exists(unit, debuff) end,
		LeftOnCast = function(unit, time) if ccR.Unit.Exists(unit) then local name, _, _, _, _, endTime = UnitCastingInfo(unit)	if name ~= nil then	if ((endTime/1000) - GetTime()) <= time then return true else return false end end end end,
		LeftOnChannel =	function(unit, time) if ccR.Unit.Exists(unit) then local name, _, _, _, _, endTime = UnitChannelInfo(unit) if name ~= nil then if time >= ((endTime/1000) - GetTime()) then return true else return false end end end end,
		My = {
			Aura = function(unit, aura) return ccR.Unit.Aura.Exists(unit, aura, true) end,
			Buff = function(unit, buff) return ccR.Unit.Buff.Exists(unit, buff, true) end,
			Debuff = function(unit, debuff) return ccR.Unit.Debuff.Exists(unit, debuff, true) end,
		},
		MyBuff = function(unit, buff) return ccR.Unit.Buff.Exists(unit, buff, true) end,
		MyDebuff = function(unit, debuff) return ccR.Unit.Debuff.Exists(unit, debuff, true) end,
		Target = function(unit) if ccR.Unit.Exists(unit) and UnitTarget(unit) ~= nil then return true else return false end end,
	},
	Is = {
		Alive = function(unit) if ccR.Unit.Exists(unit) then if UnitHealth(unit) > 1 then return true else return false end else return false end end,
		A = {
			Player = function(unit) return ccR.Unit.Is.APlayer(unit) end,
			Pet = function(unit) return ccR.Unit.Is.APet(unit) end,
		},
		APlayer =
		function(unit) 
			if ccR.Unit.Exists(unit) then 
				if (UnitIsPlayer(unit) and strsub(UnitGUID(unit) or "", 1, 6) == "Player")
				or ccR.Unit.Is.Proving_Grounds(unit)
				then
					return true
				else
					return false
				end
			else
				return false
			end
		end,
		APet = function(unit) if ccR.Unit.Exists(unit) and strsub(UnitGUID(unit) or "", 1, 3) == "Pet" then return true else return false end end,
		Attackable = function(unit, other) if other == nil then other = "player" end if ccR.Unit.Exists(unit) and ccR.Unit.Exists(other) and ccR.Unit.Is.Alive(unit) and ccR.Unit.Is.Alive(other) and UnitCanAttack(unit, other) then return true else return false end end,
		Boss = function(unit) if ccR.Unit.Exists(unit) then if tContains(ccR.Boss, ccR.Unit.NPCID(unit)) then return true else return false end else return false end end,
		Casting =
		function(unit)
			if ccR.Unit.Exists(unit)
			and UnitCastingInfo(unit) ~= nil 
			then
				local _, _, _, _, startTime, endTime, _, _, _ = UnitCastingInfo(unit)
				if GetTime() < endTime then
					return true
				else
					return false
				end
			else
				return false
			end
		end,
		CastingAtPlayer = function(unit) if ccR.Unit.Exists(unit) and ccR.Unit.Has.Target(unit) and ccR.Unit.TargetName(unit) == ccR.Player.Name() and ccR.Unit.Is.Casting(unit) then return true	else return false end end,	
		CastingSpell =
		function(unit, spell) 
			if ccR.Unit.Exists(unit)
			and ccR.Unit.Is.Casting(unit)
			then
				local IDToName 
				if tonumber(spell) ~= nil then IDToName = GetSpellInfo(spell) end
				local name, subText, text, texture, startTime, endTime, isTradeSkill, castID, notInterruptible = UnitCastingInfo(unit)
				if name == spell
				or name == IDToName
				or castID == spell
				then 
					return true
				else
					return false
				end
			else
				return false
			end
		end,
		CastingOrChanneling = function(unit) if ccR.Unit.Exists(unit) then if ccR.Unit.Is.Casting(unit) or ccR.Unit.Is.Channeling(unit) then return true else return false end else return false end end,
		CastingOrChannelingAtPlayer = function(unit) if ccR.Unit.Exists(unit) then if ccR.Unit.Is.CastingAtPlayer(unit) or ccR.Unit.Is.ChannelingAtPlayer(unit) then return true else return false end else return false end end,
		CastingWhatSpell =
		function(unit) 
			if ccR.Unit.Exists(unit)
			and ccR.Unit.Is.Casting(unit)
			then
				local name, subText, text, texture, startTime, endTime, isTradeSkill, castID, notInterruptible = UnitCastingInfo(unit)
				if castID ~= nil then return castID end
			end
		end,
		Channeling =
		function(unit) 
			if ccR.Unit.Exists(unit)
			and UnitChannelInfo(unit) ~= nil 
			then
				local _, _, _, _, startTime, endTime, _, _ = UnitChannelInfo(unit)
				if GetTime() < endTime then
					return true
				else
					return false
				end
			else
				return false
			end
		end,
		ChannelingSpell =
		function(unit, spell) 
			if ccR.Unit.Exists(unit)
			and ccR.Unit.Is.Channeling(unit)
			then
				if tonumber(spell) ~= nil then spell = GetSpellInfo(spell) end 
				local name, subText, text, texture, startTime, endTime, isTradeSkill, notInterruptible = UnitChannelInfo(unit) 
				if name == spell then 
					return true
				else
					return false
				end
			else
				return false
			end
		end,
		ChannelingAtPlayer = function(unit) if ccR.Unit.Exists(unit) then if ccR.Unit.HasTarget(unit) and ccR.Unit.TargetName(unit) == ccR.Player.Name() and ccR.Unit.Is.Channeling(unit) then return true	else return false end	end	end,	
		ChannelingWhatSpell =
		function(unit) 
			if ccR.Unit.Exists(unit)
			and ccR.Unit.Is.Channeling(unit)
			then
				local name, subText, text, texture, startTime, endTime, isTradeSkill, castID, notInterruptible = UnitCastingInfo(unit)
				if castID ~= nil then return castID end
			end
		end,
		CC = 
		function(unit)
			local tbl = {
				3355, 	-- Freezing Trap
				19386, 	-- Wyvern Sting
				8122, 	-- Psychic Scream
				118, 	-- Polymorph
				82691, 	-- Ring of Frost
				115078, -- Paralysis
				105421, -- Blinding Light
				20066, 	-- Repentance
				1776, 	-- Gouge
				6770, 	-- Sap
				2094, 	-- Blind
				51514, 	-- Hex
				118699, -- Fear
				5484, 	-- Howl of Terror
				115268, -- Mesmerize (Shivarra)
				6358, 	-- Seduction (Succubus)	
				5246, 	-- Intimidating Shout
			}
			if ccR.Unit.Exists(unit) then
				for i = 1, #tbl do if ccR.Unit.Has.Debuff(unit, tbl[i]) then return true end end
				return false
			else
				return false
			end
		end,
		Dead = function(unit) if ccR.Unit.Exists(unit) then if UnitHealth(unit) == 0 then return true else return false end end end,
		DPS = function(unit) if ccR.Unit.Exists(unit) then if UnitGroupRolesAssigned(unit) == "DAMAGER" then return true else return false end end end,
		Dummy = function(unit) if tContains(ccR.tblUnitCountAsOne, ccR.Unit.NPCID(unit)) then return true else return false end end,
		Elite = function(unit) if ccR.Unit.Exists(unit) then if UnitClassification(unit) == "elite" then return true else return false end end end,
		EnemyPlayer = function(unit) if ccR.Unit.Exists(unit) then if UnitIsEnemy("player", unit) and UnitCanAttack("player", unit) and UnitIsPlayer(unit) then return true else return false end end end,
		ExactFacing =
		function(unit, other, num)
			if num == nil then num = 0.2 end
			if ccR.Unit.Exists(unit)
			and ccR.Unit.Exists(other)
			then
				local X1, Y1 = ObjectPosition(unit)
				local X2, Y2 = ObjectPosition(other)
				local IsExactFacing = abs(ObjectFacing(unit) - rad(atan2(Y2 - Y1, X2 - X1))) < num
				if IsExactFacing then
					return true
				else
					return false
				end
			else
				return false
			end
		end,
		Facing = function(unit, other)
			if ccR.Unit.Exists(unit) 
			and ccR.Unit.Exists(other) 
			then
				local X, Y, Z = ObjectPosition(unit);
				local Rotation = ObjectFacing(unit); 
				local OtherX, OtherY = ObjectPosition(other) 
				return ((X - OtherX) * math.cos(-Rotation)) - ((Y - OtherY) * math.sin(-Rotation)) < 0 
			end
		end,
		Frozen = 
		function(unit)
			if ccR.Unit.Exists(unit) then
				if ccR.Unit.Has.My.Debuff(unit, 122) -- Frost Nova
				or ccR.Unit.Has.My.Debuff(unit, 33395) -- Freeze
				or ccR.Unit.Has.My.Debuff(unit, 111340) -- Ice Ward
				or ccR.Unit.Has.My.Debuff(unit, 44572) -- Deep Freeze
				or ccR.Unit.Has.My.Debuff(unit, 102051) -- Frostjaw
				or ccR.Unit.Has.My.Debuff(unit, 157997) -- Ice Nova
				then
					return true
				else
					return false
				end
			else
				return false
			end
		end,
		Ghost = function(unit) return UnitIsGhost(unit) end,
		Healer = function(unit) if ccR.Unit.Exists(unit) then if UnitGroupRolesAssigned(unit) == "HEALER" then return true else return false end end end,
		In = {
			Combat = function(unit) return ccR.Unit.Is.InCombat(unit) end,
			LineOfSight = function(unit, other, flag) return ccR.Unit.Is.InLineOfSight(unit, other, flag) end,
		},
		InCombat = 
		function(unit) 
			if ccR.Unit.Exists(unit) then
				--if unit == "player" and #ccR_Enemies_In_Combat == 0 then return false end
				if UnitAffectingCombat(unit) then return true else return false	end
			end 
		end,
		InLineOfSight = 
		function(unit, other, flag)
			if other == nil then other = "player" end
			if flag == nil then flag = 0x10 end
			-- 0x100011
			if ccR.Unit.Exists(unit)
			and ccR.Unit.Exists(other)
			then
				if tbl_Ignore_LoS_Units[ccR.Unit.NPCID(unit)] then
					return true
				else
					local X1, Y1, Z1 = ObjectPosition(unit) local X2, Y2, Z2 = ObjectPosition(other) 
					local IsInLoS = not TraceLine(X1, Y1, Z1 + (Increase or 2), X2, Y2, Z2 + (Increase or 2), flag)
					if IsInLoS then	return true else return false end
				end
			end
		end,
		Interuptable = function(unit) if ccR.Unit.Exists(unit) and not ccR.Unit.Has.Buff("Divine Shield") and not ccR.Unit.Has.Buff("Unending Resolve") and not ccR.Unit.Has.Buff("Hand of Protection") and not ccR.Unit.Has.Buff("Devotion Aura") then if ccR.Unit.Is.Casting(unit) then local _, _, _, _, _, _, _, _, notInterruptible = UnitCastingInfo(unit) if notInterruptible == false then return true else return false end end if ccR.Unit.Is.Channeling(unit) then local _, _, _, _, _, _, _, notInterruptible = UnitChannelInfo(unit) if notInterruptible == false then return true else return false end end else return false end end,

		ImmuneToAll = function(unit) return ccR.Unit.Is.Immune.To.All(unit) end,
		ImmuneToMagic = function(unit) return ccR.Unit.Is.Immune.To.Magic(unit) end,
		ImmuneToPhysical = function(unit) return ccR.Unit.Is.Immune.To.Physical(unit) end,
		ImmuneToSnare = function(unit) return ccR.Unit.Is.Immune.To.Snare(unit) end,
		Immune = {
			To = {
				All = 
				function(unit)
					if ccR.Unit.Exists(unit) then
						local tblAll = {
							33786, 	-- Cyclone
							45438, 	-- Ice Block
							642, 	-- Divine Shield
							19263, 	-- Deterrence
						}
						for i = 1, # tblAll do
							if ccR.Unit.Has.Aura(unit, tblAll[i]) then return true end
						end
						return false
					else
						return false
					end
				end,
				Magic =
				function(unit)
					if ccR.Unit.Exists(unit) then
						local tblMagic = {
							31224, -- Cloak of Shadows
							48707, -- Anti-Magic Shell
							23920, -- Spell Reflect
						}
						for i = 1, # tblMagic do
							if ccR.Unit.Has.Aura(unit, tblMagic[i]) or ccR.Unit.Is.Immune.To.All(unit) then return true end
						end
						return false
					else
						return false
					end
				end,
				Physical =
				function(unit)
					if ccR.Unit.Exists(unit) then
						local tblPhysical = {
							1022, 	-- Hand of Protection
						}
						local tblPhysicalBehind = {
							5277,	-- Evasion
							118038, -- Die by the Sword
						}
						for i = 1, # tblPhysical do if ccR.Unit.Has.Aura(unit, tblPhysical[i]) or ccR.Unit.Is.Immune.To.All(unit) then return true end end
						for i = 1, # tblPhysicalBehind do if (ccR.Unit.Has.Aura(unit, tblPhysicalBehind[i]) and not ccR.Player.Is.Behind(unit)) or ccR.Unit.Is.Immune.To.All(unit) then return true end end
						return false
					else
						return false
					end
				end,
				Snare =
				function(unit)
					if ccR.Unit.Exists(unit) then
						local tblSnare = {
							1044, 	-- Hand of Freedom
							53271, 	-- Masters Call
							108273, -- Windwalk Totem
						}
						for i = 1, # tblSnare do
							if ccR.Unit.Has.Aura(unit, tblSnare[i]) or ccR.Unit.Is.Immune.To.All(unit) then return true end
						end
						return false
					else
						return false
					end
				end,
			},
		},

		Moving = function(unit) if ccR.Unit.Exists(unit) then if GetUnitSpeed(unit) ~= 0 then return true else return false end else return false end end,
		Normal = function(unit) if ccR.Unit.Exists(unit) then if UnitClassification(unit) == "normal" then return true else return false end end end,
		Not = {
			Player = function(unit) return ccR.Unit.Is.NotPlayer(unit) end,
		},
		NotPlayer =
		function(unit) 
			if ccR.Unit.Exists(unit) then 
				if ccR.Unit.GUID(unit) ~= ccR.Unit.GUID("player") then 
					return true 
				else 
					return false 
				end
			else 
				return false 
			end 
		end,
		Player = 
		function(unit)
			if ccR.Unit.Exists(unit) then 
				if ccR.Unit.GUID(unit) == ccR.Unit.GUID("player") then 
					return true 
				else 
					return false 
				end
			else 
				return false 
			end 
		end,
		Proving_Grounds = 
		function(unit)
			tbl_Units = {
				72218, -- Oto the Protector
				72220, -- Sooli the Survivalist
				72221, -- Kavan the arcanist
				72219, -- Ki the assassin
			}
			if tContains(tbl_Units, ccR.Unit.NPCID(unit)) then
				return true
			else
				return false
			end
		end,
		Rare = function(unit) if ccR.Unit.Exists(unit) then local vType = UnitClassification(unit) if vType == "rare" or vType == "rareelite" then return true else return false end end end,
		Tank = 
		function(unit) 
			if ccR.Unit.Exists(unit) then 
				if UnitGroupRolesAssigned(unit) == "TANK" or ccR.Unit.NPCID(unit) == 72218 then 
					return true 
				else 
					return false 
				end 
			else
				return false
			end 
		end,
		Tapped = function(unit) if ccR.Unit.Exists(unit) then if UnitIsTapped(unit) then return true else return false end end end,
		TappedByPlayer = function(unit) if ccR.Unit.Exists(unit) then if UnitIsTappedByPlayer(unit) then return true else return false end end end,
		TargetingPlayer = function(unit) if ccR.Unit.Exists(unit) then if ccR.Unit.HasTarget(unit) and ccR.Unit.TargetName(unit) == ccR.Player.Name() then return true else return false end end end,
		Visible = function(unit) if ccR.Unit.Exists(unit) then return UnitIsVisible(unit) else return false end end,
		VisibleOnScreen = function(unit)
			if type(WorldToScreen) == "function" then
				if ccR.Unit.Exists(unit) then
					local X, Y = WorldToScreen(ObjectPosition(unit))
					if X == nil or Y == nil then return false end
					if  X > 0 and X < 1 
					and Y > 0 and Y < 1 then return true end

					Y = -Y
					if (	
							X > WorldFrame:GetRight()
						or 	X < WorldFrame:GetLeft()
						or 	Y > WorldFrame:GetTop()
						or 	Y < 0
						) 
					then
						return false
					else
						return true
					end
				else
					return false
				end
			else
				return true
			end
		end,
		WithinMelee = function(unit, other) if ccR.Unit.Exists(unit) and ccR.Unit.Exists(other) then local X1,Y1,Z1 = ObjectPosition(unit) local X2,Y2,Z2 = ObjectPosition(other) local vDistance = math.sqrt(((X2-X1)^2)+((Y2-Y1)^2)+((Z2-Z1)^2)) if ccR.Unit.Is.Moving(unit) and ccR.Unit.Is.Moving(other) then if vDistance < max(5, UnitCombatReach(unit) + UnitCombatReach(other) + 4/3) + 8/3 then return true else return false end else if vDistance < max(5, UnitCombatReach(unit) + UnitCombatReach(other) + 4/3) then return true else return false end end end end,
		WithinRanged = function(unit, other, spellrange) if ccR.Unit.Exists(unit) and ccR.Unit.Exists(other) then local X1,Y1,Z1 = ObjectPosition(unit) local X2,Y2,Z2 = ObjectPosition(other) local vDistance = math.sqrt(((X2-X1)^2)+((Y2-Y1)^2)+((Z2-Z1)^2)) if ccR.Unit.Is.Moving(unit) and ccR.Unit.Is.Moving(other) then if vDistance < UnitCombatReach(unit) + UnitCombatReach(other) + spellrange + 2 then return true else return false end else if vDistance < UnitCombatReach(unit) + UnitCombatReach(other) + spellrange then return true else return false end end end end,
		WithinAOE = function(unit, other, spellrange) if ccR.Unit.Exists(unit) and ccR.Unit.Exists(other) then local X1,Y1,Z1 = ObjectPosition(unit) local X2,Y2,Z2 = ObjectPosition(other) local vDistance = math.sqrt(((X2-X1)^2)+((Y2-Y1)^2)+((Z2-Z1)^2)) if vDistance < UnitCombatReach(other) + spellrange then return true else return false end end end,
		WorldBoss = function(unit) if ccR.Unit.Exists(unit) then if UnitClassification(unit) == "worldboss" then return true else return false end end end,
	},
	--
	-- OLD
	--
		CanAttack = function(unit, other) return ccR.Unit.Can.Attack(unit,other) end,
		BuffStacks = function(unit, buff) return ccR.Unit.Buff.Stacks(unit, buff) end,
		BuffDuration = function(unit, buff, by, number) return ccR.Unit.Buff.Duration(unit, buff, by, number) end,
		DebuffStacks = function(unit, debuff) return ccR.Unit.Debuff.Stacks(unit, debuff) end,
		DebuffDuration = function(unit, debuff, by, number) return ccR.Unit.Debuff.Duration(unit, debuff, by, number) end,
		MyBuffDuration = function(unit, buff, by, number) return ccR.Unit.Buff.Duration(unit, buff, by, number, true) end,
		MyDebuffDuration = function(unit, debuff, by, number) return ccR.Unit.My.Debuff.Duration(unit, debuff, by, number, true) end,
		HasBuff = function(unit, buff) return ccR.Unit.Has.Buff(unit, buff) end,
		HasDebuff = function(unit, debuff) return ccR.Unit.Has.Debuff(unit, debuff) end,
		HasLeftOnCast = function(unit, time) return ccR.Unit.Has.LeftOnCast(unit, time) end,
		HasLeftOnChannel = function(unit, time) return ccR.Unit.Has.LeftOnChannel(unit, time) end,
		HasMyBuff = function(unit, buff) return ccR.Unit.Has.MyBuff(unit, buff) end,
		HasMyDebuff = function(unit, debuff) return ccR.Unit.Has.MyDebuff(unit, debuff) end,
		HasTarget = function(unit) return ccR.Unit.Has.Target(unit) end,
		IsAlive = function(unit) return ccR.Unit.Is.Alive(unit) end,
		IsAPlayer = function(unit) return ccR.Unit.Is.APlayer(unit) end,
		IsAttackable = function(unit, other) return ccR.Unit.Is.Attackable(unit, other) end,
		IsBoss = function(unit) return ccR.Unit.Is.Boss(unit) end,
		IsCasting = function(unit) return ccR.Unit.Is.Casting(unit) end,
		IsCastingAtPlayer = function(unit) return ccR.Unit.Is.CastingAtPlayer(unit) end,
		IsCastingSpell = function(unit, spell) return ccR.Unit.Is.CastingSpell(unit, spell) end,
		IsCastingOrChanneling = function(unit) return ccR.Unit.Is.CastingOrChanneling(unit) end,
		IsChanneling = function(unit) return ccR.Unit.Is.Channeling(unit) end,
		IsChannelingSpell = function(unit, spell) return ccR.Unit.Is.ChannelingSpell(unit, spell) end,
		IsChannelingAtPlayer = function(unit) return ccR.Unit.Is.ChannelingAtPlayer(unit) end,
		IsDead = function(unit) return ccR.Unit.Is.Dead(unit) end,
		IsDPS = function(unit) return ccR.Unit.Is.DPS(unit) end,
		IsElite = function(unit) return ccR.Unit.Is.Elite(unit) end,
		IsEnemyPlayer = function(unit) return ccR.Unit.Is.EnemyPlayer(unit) end,
		IsFacing = function(unit, other) return ccR.Unit.Is.Facing(unit, other) end,
		IsHealer = function(unit) return ccR.Unit.Is.Healer(unit) end,
		IsInCombat = function(unit) return ccR.Unit.Is.InCombat(unit) end,
		IsInLineOfSight = function(unit, other) return ccR.Unit.Is.InLineOfSight(unit, other) end,
		IsInteruptable = function(unit) return ccR.Unit.Is.Interuptable(unit) end,
		IsMoving = function(unit) return ccR.Unit.Is.Moving(unit) end,
		IsNormal = function(unit) return ccR.Unit.Is.Normal(unit) end,
		IsRare = function(unit) return ccR.Unit.Is.Rare(unit) end,
		IsTank = function(unit) return ccR.Unit.Is.Tank(unit) end,
		IsTapped = function(unit) return ccR.Unit.Is.Tapped(unit) end,
		IsTappedByPlayer = function(unit) return ccR.Unit.Is.TappedByPlayer(unit) end,
		IsTargetingPlayer = function(unit) return ccR.Unit.Is.TargetingPlayer(unit) end,
		IsWithinMelee = function(unit, other) return ccR.Unit.Is.WithinMelee(unit, other) end,
		IsWithinRanged = function(unit, other, spellrange) return ccR.Unit.Is.WithinRanged(unit, other, spellrange) end,
		IsWithinAOE = function(unit, other, spellrange) return ccR.Unit.Is.WithinAOE(unit, other, spellrange) end,
		IsWorldBoss = function(unit) return ccR.Unit.Is.WorldBoss(unit) end,
}
ccR.Unit.__index = ccR.Unit

function FH(API, ...)
	local pStatus, pReturn = pcall(API, ...)
	if pStatus and pReturn ~= nil then return pReturn end
end